/**
 * 
 */
package com.example.demo.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baidubce.auth.DefaultBceCredentials;
import com.baidubce.services.sms.SmsClient;
import com.baidubce.services.sms.SmsClientConfiguration;
import com.baidubce.services.sms.model.SendMessageV3Request;
import com.baidubce.services.sms.model.SendMessageV3Response;

/**
 * @author 030998
 *
 */
@Controller
@RequestMapping("/sms")
public class BaiduSmsController {
	
	@RequestMapping("/send")
	public void sms() {
		String ACCESS_KEY_ID = "your access key";
        String SECRET_ACCESS_KEY = "your secret key";
        String ENDPOINT = "http://smsv3.bj.baidubce.com";

        SmsClientConfiguration config = new SmsClientConfiguration();
        config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY));
        config.setEndpoint(ENDPOINT);
        SmsClient client = new SmsClient(config);

        SendMessageV3Request request = new SendMessageV3Request();
        request.setMobile("13857826983");
        request.setSignatureId("sms-signQxkiwz88470");
        request.setTemplate("sms-tmpl-awKvRY85349");
        Map<String, String> contentVar = new HashMap<>();
        contentVar.put("code", "23456");
        contentVar.put("minute", "1");
        request.setContentVar(contentVar);
        SendMessageV3Response response = client.sendMessage(request);
        if(response != null && response.isSuccess()) {
        	System.out.println("sms successful");
        } else {
        	System.out.println("sms error");
        }
	}

}
